<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;


class PersonalGuanzhu extends IndexController
{
    public function index()
    {

        $guanzhu = Db::query("select u.icon,u.nickname,u.sex,u.id,u.sightml,u.province from bbs_user u,bbs_friend f where f.use_id=".input('session.user.id')." and f.fid=u.id");
        $this->assign('guanzhuList', $guanzhu);
        $this->assign('gzcount',count($guanzhu));

        $guanzhumy = Db::query("select u.icon,u.nickname,u.sex,u.id,u.sightml,u.province from bbs_user u,bbs_friend f where f.fid=".input('session.user.id')." and f.use_id=u.id");
        $this->assign('gzmyList', $guanzhumy);
        $this->assign('gzmycount',count($guanzhumy));

        $allguanzhu = Db::query('select u.icon,u.nickname,u.sex,u.id,u.sightml,u.province from bbs_user u where u.id in (select t1.fid from (select * from bbs_friend where use_id = '.input('session.user.id').') as t1 inner join (select * from bbs_friend where fid = '.input('session.user.id').') as t2 on t1.fid = t2.use_id)');
        $this->assign('allgzList', $allguanzhu);
        $this->assign('allcount',count($allguanzhu));

        $black = Db::query("select * from bbs_user u,bbs_blacklist b where b.use_id=".input('session.user.id')." and b.hid=u.id");
        $this->assign('blackList', $black);
        $this->assign('blackcount',count($black));



        return view('personal_guanzhu/index');
    }



    public function addguanzhu()
    {
        $data = ['use_id'=>input('session.user.id'),'fid'=>input('id')];
        $result = db('friend')->insert($data);
        if($result){
            db('blacklist')->where('use_id',input('session.user.id'))->where('hid',input('id'))->delete();
            return json($result);
        }
    }


    public function delguanzhu()
    {

        $result = db('friend')->where('use_id',input('session.user.id'))->where('fid',input('id'))->delete();
        return json($result);
        
    }


    public function lahei()
    {
        $data = ['use_id'=>input('session.user.id'),'hid'=>input('id')];
        $result = db('blacklist')->insert($data);
        if($result){
            db('friend')->where('use_id',input('session.user.id'))->where('fid',input('id'))->delete();
            return json($result);
        }

        
    }



    public function qxlahei()
    {

        $result = db('blacklist')->where('use_id',input('session.user.id'))->where('hid',input('id'))->delete();
        return json($result);
    }



}